package com.fang.networkdisk.controller;

import com.fang.common.common.CommonPage;
import com.fang.common.common.CommonResult;
import com.fang.common.request.BaseController;
import com.fang.common.util.CommonResultUtil;
import com.fang.networkdisk.entity.bo.UserRoleRelationBo;
import com.fang.networkdisk.entity.dto.UserRoleRelationDto;
import com.fang.networkdisk.entity.vo.UserRoleRelationVo;
import com.fang.networkdisk.service.TbNetDisUserRoleRelationService;
import com.fang.networkdisk.util.NDBeanUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description
 * @Author Bernie_fang
 * @Date 2025/3/18 21:34
 **/
@RestController
@RequestMapping("/system/userRoleRelation")
public class UserRoleRelationController extends BaseController {

    @Resource
    private TbNetDisUserRoleRelationService tbNetDisUserRoleRelationService;

    @PostMapping("/list")
    public CommonResult<CommonPage<List<UserRoleRelationVo>>> queryUserRoleRelation(@RequestBody UserRoleRelationDto userRoleRelationDto) {
        UserRoleRelationBo userRoleRelationBo = new UserRoleRelationBo();
        NDBeanUtils.copyListProperties(userRoleRelationDto, userRoleRelationBo);
        CommonPage result = tbNetDisUserRoleRelationService.queryUserRoleRelation(userRoleRelationBo);
        return CommonResultUtil.success(result);
    }

    @PostMapping("/add")
    public CommonResult<CommonPage<List<UserRoleRelationVo>>> addUserRoleRelation(@RequestBody UserRoleRelationDto userRoleRelationDto) {
        String authorId = super.getAuthorId();
        UserRoleRelationBo userRoleRelationBo = new UserRoleRelationBo();
        NDBeanUtils.copyListProperties(userRoleRelationDto, userRoleRelationBo);
        userRoleRelationBo.setCreateUser(authorId);
        userRoleRelationBo.setUpdateUser(authorId);
        tbNetDisUserRoleRelationService.addUserRoleRelation(userRoleRelationBo);
        return CommonResultUtil.success();
    }

    /**
     * Description: 修改用户账号信息，不修改用户id，用户名，密码
     *
     * @param userRoleRelationDto:
     * @Author: Bernie_fang
     * @Since: 2025/3/1 22:15
     * @return: com.fang.common.common.CommonResult<com.fang.common.common.CommonPage < java.util.List < com.fang.networkdisk.entity.vo.UserRoleRelationVo>>>
     **/
    @PostMapping("/update")
    public CommonResult<CommonPage<List<UserRoleRelationVo>>> updateUserRoleRelation(@RequestBody UserRoleRelationDto userRoleRelationDto) {
        String authorId = super.getAuthorId();
        UserRoleRelationBo userRoleRelationBo = new UserRoleRelationBo();
        NDBeanUtils.copyListProperties(userRoleRelationDto, userRoleRelationBo);
        userRoleRelationBo.setCreateUser(null);
        userRoleRelationBo.setUpdateUser(authorId);
        tbNetDisUserRoleRelationService.updateUserRoleRelationById(userRoleRelationBo);
        return CommonResultUtil.success();
    }

    @GetMapping("/delete/{id}")
    public CommonResult<CommonPage<List<UserRoleRelationVo>>> deleteUserRoleRelation(@PathVariable("id") Integer id) {
        String authorId = super.getAuthorId();
        tbNetDisUserRoleRelationService.deleteUserRoleRelationById(id, authorId);
        return CommonResultUtil.success();
    }


}
